package com.chase.chasecat.common;

import lombok.Data;

import java.io.Serializable;

@Data
public class R<T> implements Serializable {
    /**
     * 状态码
     */
    private int code;

    /**
     * 返回信息
     */
    private String message;

    /**
     * 内容
     */
    private T data;

    public R() {
    }

    public R(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static R ok(String message){
        return newR(200,message,null);
    }

    public static R fail(String message){
        return newR(500,message,null);
    }

    public static R ok(int code,String message){
        return newR(code,message,null);
    }

    public static R fail(int code,String message){
        return newR(code,message,null);
    }

    public static R ok(String message,Object data){
        return newR(200,message,data);
    }

    public static R fail(String message,Object data){
        return newR(500,message,data);
    }

    public static R ok(Object data){
        return newR(200,"访问失败",data);
    }

    public static R fail(Object data){
        return newR(500,"访问失败",data);
    }

    private static R newR(int code,String message,Object data){
        R r = new R(code,message,data);
        return r;
    }
}
